from option import Option

class Chat:
	def announceEnter(self, user):
		self.send('sys', '%s has entered the chatroom.' % user.name)
		self.notify('enter', user.getInfo())

	def announceLeave(self, user):
		self.send('sys', '%s has left the chatroom.' % user.name)
		self.notify('leave', user.getInfo())

	def send(self, sender, msg):
		message = '%s: %s' % (sender, msg)

		Option().chatLog.info(message)

		for user in Option().users:
			user.send(message)

	def notify(self, param1, param2):
		Option().chatLog.debug('Notification: %s %s' %(str(param1), str(param2)))

		for user in Option().users:
			user.notify(param1, param2)
